package io.gitee.kotle.player.ui.view.exo

import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import androidx.media3.common.MediaItem
import io.gitee.kotle.player.core.IPlayer
import io.gitee.kotle.player.core.impl.exoplayer.IExoPlayerMode
import kotlinx.coroutines.CoroutineScope

/**
 * 标题view
 */
class ExoPlayerTitleView : AppCompatTextView, IExoPlayerView {

    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    override fun needPlayerListener(): Boolean {
        return true
    }

    override suspend fun onModelChange(
        scope: CoroutineScope,
        player: IPlayer<MediaItem, IExoPlayerMode>,
        oldModel: IExoPlayerMode?,
        newModel: IExoPlayerMode
    ) {
        super.onModelChange(scope, player, oldModel, newModel)
        text = newModel.getTitle(scope, player)
    }
}